package com.syni.mdd.yhd.common.all.quartz.order;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.*;
import com.syni.mdd.yhd.common.all.entity.platformGood.BmsPlatformGood;
import com.syni.mdd.yhd.common.all.service.*;
import com.syni.mdd.yhd.common.all.service.platformGoods.BmsPlatformGoodService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ArithUtil;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.sjb.common.component.utils.redis.utils.RedisTemplateUtils;;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import com.syni.mdd.sjb.common.component.utils.feign.service.mddDistSys.FxCenterService;
import io.seata.spring.annotation.GlobalTransactional;
import org.quartz.CronTrigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.*;

/**
 * @className BmsUserVideoLikeQuartz
 * @description 定时任务（一天一次，扫描的商家点赞数）
 * @Author cfx
 * @DATE 2019/4/18 16:57
 * @VERSION 1.0
 **/
@Component
@EnableScheduling
public class OrderSellStatisticalQuartz{

    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    BmsDxOrderStatusService bmsDxOrderStatusService;

    @Autowired
    BmsDxCouponService bmsDxCouponService;

    @Autowired
    BmsDxOrderService bmsDxOrderService;

    @Autowired
    BmsDxGroupBuyService bmsDxGroupBuyService;

    @Autowired
    BmsDxGroupBuyUseService bmsDxGroupBuyUseService;


    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    BmsPlatformGoodService bmsPlatformGoodService;

    @Autowired
    FxCenterService fxCenterService;

    /**
     * @Description 统计排行榜（成交金额）
     * @Author cfx
     * @Date: 2019/9/22
     */
    @Scheduled(cron = "0 0 0 * * ?")  //每天晚上凌晨执行一次定时任务
    //@Scheduled(cron = "0/5 * * * * ?")
    public void countOrderSellNum(){
        //统计线上买单的销售量
        Date nowTime = new Date();
        System.out.println("计算时间：" + nowTime.getTime());

        Date startTime = DateTimeUtils.getStartTimeOfDay(DateTimeUtils.addDay(nowTime,-1));
        System.out.println("开始时间：" + startTime.getTime());

        Date endTime = DateTimeUtils.getEndTimeOfDay(startTime);
        System.out.println("结束时间：" + endTime.getTime());
        //买单订单用户消费
        countUserConsumptionByPayOrder(startTime,endTime);
        //团购订单用户消费
        countUserConsumptionByGroupBuyOrder(startTime,endTime);
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void handlePlatformNoCommitSuccess(){
        String redisKey = Constants.REDIS_KEY_PLATFORM_GOOD_IN;
        long size = redisTemplate.opsForZSet().size(redisKey);
        if(size > 0) {
            Set<ZSetOperations.TypedTuple> setRedis = redisTemplate.opsForZSet().rangeWithScores(redisKey, 0, size);
            Map<Integer, Integer> goodNum = new HashMap<>();
            for (ZSetOperations.TypedTuple typedTuple : setRedis) {
                String[] goodData = typedTuple.getValue().toString().split(":");
                Integer goodId = Integer.parseInt(goodData[1]);
                Integer num = typedTuple.getScore().intValue();
                if (!goodNum.containsKey(goodId)) {
                    goodNum.put(goodId, 0);
                }
                goodNum.put(goodId, goodNum.get(goodId) + num);
            }
            if (goodNum.size() > 0) {
                for (Map.Entry<Integer, Integer> obj : goodNum.entrySet()) {
                    BmsPlatformGood bmsPlatformGood = bmsPlatformGoodService.findById(obj.getKey());
                    if (bmsPlatformGood != null) {
                        bmsPlatformGoodService.updateLoseGoodInventory(bmsPlatformGood.getId(), obj.getValue(), bmsPlatformGood.getVersion());
                    }
                }
            }
        }
    }

    private void countUserConsumptionByGroupBuyOrder(Date startTime, Date endTime) {
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("status",Constants.GROUP_ALREADY_USE);
        conditionMap.put("useTime_GTTE",startTime);
        conditionMap.put("useTime_LTT",endTime);
        List<BmsDxGroupBuyUse> bmsDxGroupBuyUses = bmsDxGroupBuyUseService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        //统计金额
        if(bmsDxGroupBuyUses != null && bmsDxGroupBuyUses.size() > 0){
            Map<Integer,Double> totalMap = new HashMap<>();
            for(BmsDxGroupBuyUse bmsDxGroupBuyUse : bmsDxGroupBuyUses){
                if(!totalMap.containsKey(bmsDxGroupBuyUse.getUserId())){
                    totalMap.put(bmsDxGroupBuyUse.getUserId(),0d);
                }
                if(bmsDxGroupBuyUse.getGbuyActualConsum() != null) {
                    totalMap.put(bmsDxGroupBuyUse.getUserId(), ArithUtil.add(totalMap.get(bmsDxGroupBuyUse.getUserId()),
                            ArithUtil.add(bmsDxGroupBuyUse.getGbuyActualConsum(),bmsDxGroupBuyUse.getDiscountMoney() == null ? 0d : bmsDxGroupBuyUse.getDiscountMoney())));
                }
            }
            if(totalMap.size() > 0){
                for(Map.Entry<Integer,Double> orderUser : totalMap.entrySet()){
                    redisTemplate.opsForZSet().incrementScore(Constants.REDIS_KEY_USER_CONSUMPTION,orderUser.getKey(),Math.floor(orderUser.getValue()));
                }
            }
        }
    }

    private void countUserConsumptionByPayOrder(Date startTime, Date endTime) {
        Map<String,Object> conditionMap = new HashMap<>();
        Set<Integer> orderTypes = new HashSet<>();
        orderTypes.add(Constants.ONLINE_ORDER_TYPE);
        orderTypes.add(Constants.COUPONS_ORDER_TYPE);
        conditionMap.put("orderType_IN",orderTypes);
        conditionMap.put("status",Constants.PAY_COMPLETE);
        conditionMap.put("newTime_GTTE",startTime);
        conditionMap.put("newTime_LTT",endTime);
        List<BmsDxOrderStatus> bmsDxOrderStatusList = bmsDxOrderStatusService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        if(bmsDxOrderStatusList != null && bmsDxOrderStatusList.size() > 0){
            Set<Integer> orderIds = new HashSet<>();
            for(BmsDxOrderStatus bmsDxOrderStatus : bmsDxOrderStatusList){
                orderIds.add(bmsDxOrderStatus.getOrderId());
            }
            List<BmsDxOrder> bmsDxOrders = bmsDxOrderService.getBaseDao().findByIdIn(orderIds);
            Map<Integer,Double> orderUserMap = new HashMap<>();
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                if(!orderUserMap.containsKey(bmsDxOrder.getBmsUserId())){
                    orderUserMap.put(bmsDxOrder.getBmsUserId(),0d);
                }
                orderUserMap.put(bmsDxOrder.getBmsUserId(), ArithUtil.add(orderUserMap.get(bmsDxOrder.getBmsUserId()),ArithUtil.add(bmsDxOrder.getActualConsum()
                        ,bmsDxOrder.getDiscountConsum() == null ? 0d : bmsDxOrder.getDiscountConsum())));
            }
            if(orderUserMap.size() > 0){
                for(Map.Entry<Integer,Double> orderUser : orderUserMap.entrySet()){
                    redisTemplate.opsForZSet().incrementScore(Constants.REDIS_KEY_USER_CONSUMPTION,orderUser.getKey(),Math.floor(orderUser.getValue()));
                }
            }
        }
    }

    /**
     * @Description 统计团购订单的核销量和退款量
     * @Author: cfx
     * @Date: 2019/9/22
     */
    @Scheduled(cron = "0 0 1 * * ?")  //每天晚上凌晨执行一次定时任务
    public void countGroupBuyVerNumAndRefundNum(){
        log.info(".............countGroupBuyVerNumAndRefundNum start ..........");
        Date endTime = DateTimeUtils.getStartTimeOfDay(new Date());

        Date startTime = DateTimeUtils.addDay(endTime,-1);

        countGroupOrderUseAndRefund(startTime,endTime);
    }


    @Scheduled(cron = "0 0 0/1 * * ?")
    //@Scheduled(cron = "0/5 * * * * ?")
    public void twoHourTask(){
        //买单前缀
        final String CP = "cp";
        //团购订单前缀
        final String GB = "gb";
        log.info("..............count orderSell start.............");
        String redisKey = Constants.REDIS_KEY_ORDER_SELL_NUM;
        long size = redisTemplate.opsForZSet().size(redisKey);
        if (size > 0) {
            Set<ZSetOperations.TypedTuple> setRedis = redisTemplate.opsForZSet().rangeWithScores(redisKey, 0, size);
            List<BmsDxCoupon> bmsDxCouponList = new ArrayList<>();
            List<BmsDxGroupBuy> bmsDxGroupBuys = new ArrayList<>();
            for (ZSetOperations.TypedTuple typedTuple : setRedis) {
                String orderIdTip = typedTuple.getValue().toString();
                String[] orderData = orderIdTip.split(":");
                Integer num = typedTuple.getScore().intValue();
                Integer id = Integer.parseInt(orderData[1]);
                if (CP.equals(orderData[0])) {
                    Optional<BmsDxCoupon> bmsDxCouponOptional = bmsDxCouponService.getBaseDao().findById(id);
                    if(bmsDxCouponOptional.isPresent()) {
                        BmsDxCoupon bmsDxCoupon = bmsDxCouponOptional.get();
                        bmsDxCoupon.setSellNum(bmsDxCoupon.getSellNum() == null ? num : bmsDxCoupon.getSellNum() + num);
                        bmsDxCouponList.add(bmsDxCoupon);
                    }
                } else if(GB.equals(orderData[0])){
                    Optional<BmsDxGroupBuy> bmsDxGroupBuyOptional = bmsDxGroupBuyService.getBaseDao().findById(id);
                    if (bmsDxGroupBuyOptional.isPresent()) {
                        BmsDxGroupBuy bmsDxGroupBuy = bmsDxGroupBuyOptional.get();
                        bmsDxGroupBuy.setSellNum(bmsDxGroupBuy.getSellNum() == null ? num : bmsDxGroupBuy.getSellNum() + num);
                        bmsDxGroupBuys.add(bmsDxGroupBuy);
                    }
                }
            }
            if(bmsDxCouponList.size() > 0){
                bmsDxCouponService.getBaseDao().saveAll(bmsDxCouponList);
            }
            if(bmsDxGroupBuys.size() > 0){
                bmsDxGroupBuyService.getBaseDao().saveAll(bmsDxGroupBuys);
            }
            redisTemplate.delete(redisKey);
        }
    }

    /**
     * @Description 定时退款
     * @Author cfx
     * @Date: 2019/9/22
     */
    //@Scheduled(cron = "0 0 0/2 * * ?")  //每两个小时执行一次
    //@Scheduled(cron = "0 0/10 * * * ?")
    /*public void orderRefund() throws Exception {
        //找出所有退款中的订单
        bmsDxOrderService.orderRufund();
    }*/

    private void countGroupOrderUseAndRefund(Date startTime,Date endTime) {
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("status",Constants.GROUP_ALREADY_USE);
        conditionMap.put("useTime_GTTE",startTime);
        conditionMap.put("useTime_LTT",endTime);
        List<BmsDxGroupBuyUse> bmsDxGroupBuyUses = bmsDxGroupBuyUseService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        //统计金额
        conditionMap.clear();
        conditionMap.put("status",Constants.GROUP_REFUND_COMPLETE);
        conditionMap.put("refundTime_GTTE",startTime);
        conditionMap.put("refundTime_LTT",endTime);
        bmsDxGroupBuyUses.addAll(bmsDxGroupBuyUseService.getBaseDao().findAll(new SpecificationUtils(conditionMap)));
        if(bmsDxGroupBuyUses != null && bmsDxGroupBuyUses.size() > 0){
            Set<Integer> groupBuyIds = new HashSet<>();
            for(BmsDxGroupBuyUse bmsDxGroupBuyUse : bmsDxGroupBuyUses){
                groupBuyIds.add(bmsDxGroupBuyUse.getGroupBuyId());
            }
            Map<Integer, BmsDxGroupBuy> bmsDxGroupBuyMap = new HashMap<>();
            if(groupBuyIds.size() > 0) {
                conditionMap.clear();
                conditionMap.put("id_IN", groupBuyIds);
                List<BmsDxGroupBuy> bmsDxGroupBuys = bmsDxGroupBuyService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
                if (bmsDxGroupBuys.size() > 0) {
                    for (BmsDxGroupBuy bmsDxGroupBuy : bmsDxGroupBuys) {
                        bmsDxGroupBuyMap.put(bmsDxGroupBuy.getId(), bmsDxGroupBuy);
                    }
                }
            }
            for(BmsDxGroupBuyUse bmsDxGroupBuyUse : bmsDxGroupBuyUses){
                if(bmsDxGroupBuyMap.containsKey(bmsDxGroupBuyUse.getGroupBuyId())) {
                    BmsDxGroupBuy bmsDxGroupBuy = bmsDxGroupBuyMap.get(bmsDxGroupBuyUse.getGroupBuyId());
                    if (bmsDxGroupBuyUse.getStatus() == Constants.GROUP_ALREADY_USE){
                        bmsDxGroupBuy.setFinishNum(bmsDxGroupBuy.getFinishNum() == null ? 1 : bmsDxGroupBuy.getFinishNum() + 1);
                    }else if(bmsDxGroupBuyUse.getStatus() == Constants.GROUP_REFUND_COMPLETE){
                        bmsDxGroupBuy.setRefundNum(bmsDxGroupBuy.getRefundNum() == null ? 1 : bmsDxGroupBuy.getRefundNum() + 1);
                    }
                }
            }
            saveGroupBuy(bmsDxGroupBuyMap);
        }
    }


    /**
     * @Description 统计优惠买单销售量
     * @Author: cfx
     * @Date: 2019/8/14
     */
    public void countOrderUserConsumption(Integer type,Set status,Date startTime,Date endTime){
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("orderType",type);
        conditionMap.put("status_IN",status);
        conditionMap.put("newTime_GTTE",startTime);
        conditionMap.put("newTime_LTT",endTime);
        List<BmsDxOrderStatus> bmsDxOrderStatusList = bmsDxOrderStatusService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        if(bmsDxOrderStatusList != null && bmsDxOrderStatusList.size() > 0){
            Set<Integer> orderIds = new HashSet<>();
            for(BmsDxOrderStatus bmsDxOrderStatus : bmsDxOrderStatusList){
                orderIds.add(bmsDxOrderStatus.getOrderId());
            }
            List<BmsDxOrder> bmsDxOrders = bmsDxOrderService.getBaseDao().findByIdIn(orderIds);
            if(type == Constants.COUPON_ONLINE){
                countCouponByOnline(bmsDxOrders);
            }else if(type == Constants.COUPONS_ORDER_TYPE){
                countCouponByPer(bmsDxOrders);
            }else if(type == Constants.GROUP_BUY_ORDER_TYPE){
                countGroupBy(bmsDxOrders);
            }else if(type == Constants.GROUP_BUY_BARGAIN_ORDER_TYPE){
                countGroupBy(bmsDxOrders);
            }
        }
    }

    /**
     * @Description 统计团购销售
     * @Author: cfx
     * @Date: 2019/8/14
     */
    public void countGroupBy(List<BmsDxOrder> bmsDxOrders) {
        if(bmsDxOrders.size() > 0){
            Set<Integer> groupBuyIds = new HashSet<>();
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                groupBuyIds.add(bmsDxOrder.getBmsGroupBuyId());
            }
            Map<Integer,BmsDxGroupBuy> bmsDxGroupBuyMap = new HashMap<>();
            if(groupBuyIds.size() > 0){
                Map<String,Object> conditionMap = new HashMap<>();
                conditionMap.put("id_IN",groupBuyIds);
                List<BmsDxGroupBuy> bmsDxGroupBuys = bmsDxGroupBuyService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
                if(bmsDxGroupBuys.size() > 0){
                    for(BmsDxGroupBuy bmsDxGroupBuy : bmsDxGroupBuys){
                        bmsDxGroupBuyMap.put(bmsDxGroupBuy.getId(),bmsDxGroupBuy);
                    }
                }
            }
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                if(bmsDxGroupBuyMap.containsKey(bmsDxOrder.getBmsGroupBuyId())){
                    BmsDxGroupBuy bmsDxGroupBuy = bmsDxGroupBuyMap.get(bmsDxOrder.getBmsGroupBuyId());
                    bmsDxGroupBuy.setSellNum(bmsDxGroupBuy.getSellNum() == null ? bmsDxOrder.getGroupBuyNum() :bmsDxGroupBuy.getSellNum() + bmsDxOrder.getGroupBuyNum());
                }
            }
            saveGroupBuy(bmsDxGroupBuyMap);
        }
    }

    public void saveGroupBuy(Map<Integer,BmsDxGroupBuy> bmsDxGroupBuyUseMap){
        if(bmsDxGroupBuyUseMap.size() > 0) {
            List<BmsDxGroupBuy> bmsDxGroupBuys = new LinkedList<>();
            for (Map.Entry<Integer, BmsDxGroupBuy> bmsDxGroupBuyEntry : bmsDxGroupBuyUseMap.entrySet()) {
                bmsDxGroupBuys.add(bmsDxGroupBuyEntry.getValue());
            }
            bmsDxGroupBuyService.getBaseDao().saveAll(bmsDxGroupBuys);
        }
    }

    /**
     * @Description 统计买单销售量（优惠买单量）
     * @Author: cfx
     * @Date: 2019/8/14
     */
    public void countCouponByPer(List<BmsDxOrder> bmsDxOrders){
        if(bmsDxOrders.size() > 0){
            countUserByPay(bmsDxOrders);
            /*Set<Integer> couponIds = new HashSet<>();
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                couponIds.add(bmsDxOrder.getBmsCouponId());
            }
            Map<Integer,BmsDxCoupon> bmsDxCouponMap = new HashMap<>();
            if(couponIds.size() > 0){
                Map<String,Object> conditionMap = new HashMap<>();
                conditionMap.put("id_IN",couponIds);
                conditionMap.put("type",Constants.COUPON_SET);
                List<BmsDxCoupon> bmsDxCoupons = bmsDxCouponService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
                if(bmsDxCoupons.size() > 0){
                    for(BmsDxCoupon bmsDxCoupon : bmsDxCoupons){
                        bmsDxCouponMap.put(bmsDxCoupon.getId(),bmsDxCoupon);
                    }
                }
            }
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                if(bmsDxCouponMap.containsKey(bmsDxOrder.getBmsCouponId())){
                    BmsDxCoupon bmsDxCoupon = bmsDxCouponMap.get(bmsDxOrder.getBmsCouponId());
                    bmsDxCoupon.setSellNum(bmsDxCoupon.getSellNum() == null ? 1 : bmsDxCoupon.getSellNum() + 1);
                }
            }
            save(bmsDxCouponMap);*/
        }
    }

    /**
     * @Description 统计买单销售量（线上买单量）
     * @Author: cfx
     * @Date: 2019/8/14
     */
    public void countCouponByOnline(List<BmsDxOrder> bmsDxOrders){
        if(bmsDxOrders.size() > 0){
            //统计成交金额
            countUserByPay(bmsDxOrders);
            //统计销售量
            /*Set<Integer> businessIds = new HashSet<>();
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                businessIds.add(bmsDxOrder.getBmsBusinessId());
            }
            Map<Integer,BmsDxCoupon> bmsDxCouponMap = new HashMap<>();
            if(businessIds.size() > 0){
                Map<String,Object> conditionMap = new HashMap<>();
                conditionMap.put("bmsBusinessId_IN",businessIds);
                conditionMap.put("type",Constants.COUPON_ONLINE);
                List<BmsDxCoupon> bmsDxCoupons = bmsDxCouponService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
                if(bmsDxCoupons.size() > 0){
                    for(BmsDxCoupon bmsDxCoupon : bmsDxCoupons){
                        bmsDxCouponMap.put(bmsDxCoupon.getBmsBusinessId(),bmsDxCoupon);
                    }
                }
            }
            for(BmsDxOrder bmsDxOrder : bmsDxOrders){
                if(bmsDxCouponMap.containsKey(bmsDxOrder.getBmsBusinessId())){
                    BmsDxCoupon bmsDxCoupon = bmsDxCouponMap.get(bmsDxOrder.getBmsBusinessId());
                    bmsDxCoupon.setSellNum(bmsDxCoupon.getSellNum() == null ? 1 : bmsDxCoupon.getSellNum() + 1);
                }
            }
            save(bmsDxCouponMap);*/
        }
    }

    public void save(Map<Integer,BmsDxCoupon> bmsDxCouponMap){
        if(bmsDxCouponMap.size() > 0) {
            List<BmsDxCoupon> bmsDxCoupons = new LinkedList<>();
            for (Map.Entry<Integer, BmsDxCoupon> bmsDxCouponEntry : bmsDxCouponMap.entrySet()) {
                bmsDxCoupons.add(bmsDxCouponEntry.getValue());
            }
            bmsDxCouponService.getBaseDao().saveAll(bmsDxCoupons);
        }
    }


    public void countUserByPay(List<BmsDxOrder> bmsDxOrders){
        Map<Integer,Double> orderUserMap = new HashMap<>();
        for(BmsDxOrder bmsDxOrder : bmsDxOrders){
            if(!orderUserMap.containsKey(bmsDxOrder.getBmsUserId())){
                orderUserMap.put(bmsDxOrder.getBmsUserId(),0d);
            }
            orderUserMap.put(bmsDxOrder.getBmsUserId(), ArithUtil.add(orderUserMap.get(bmsDxOrder.getBmsUserId()),ArithUtil.add(bmsDxOrder.getActualConsum()
                    ,bmsDxOrder.getDiscountConsum() == null ? 0d : bmsDxOrder.getDiscountConsum())));
        }
        if(orderUserMap.size() > 0){
            for(Map.Entry<Integer,Double> orderUser : orderUserMap.entrySet()){
                redisTemplate.opsForZSet().incrementScore(Constants.REDIS_KEY_USER_CONSUMPTION,orderUser.getKey(),Math.floor(orderUser.getValue()));
            }
        }
    }

    public void countUserByGroupBuy(List<BmsDxGroupBuyUse> bmsDxGroupBuyUses){
        if(bmsDxGroupBuyUses != null && bmsDxGroupBuyUses.size() > 0){
            Map<Integer,Double> totalMap = new HashMap<>();
            for(BmsDxGroupBuyUse bmsDxGroupBuyUse : bmsDxGroupBuyUses){
                if(!totalMap.containsKey(bmsDxGroupBuyUse.getUserId())){
                    totalMap.put(bmsDxGroupBuyUse.getUserId(),0d);
                }
                if(bmsDxGroupBuyUse.getGbuyActualConsum() != null) {
                    totalMap.put(bmsDxGroupBuyUse.getUserId(), ArithUtil.add(totalMap.get(bmsDxGroupBuyUse.getUserId()), bmsDxGroupBuyUse.getGbuyActualConsum()));
                }
            }
            if(totalMap.size() > 0){
                for(Map.Entry<Integer,Double> orderUser : totalMap.entrySet()){
                    redisTemplate.opsForZSet().incrementScore(Constants.REDIS_KEY_USER_CONSUMPTION,orderUser.getKey(),Math.floor(orderUser.getValue()));
                }
            }
        }

    }

    //@Override
    /*public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.addTriggerTask(
                //1.添加任务内容(Runnable)
                () -> System.out.println("执行动态定时任务: " + LocalDateTime.now().toLocalTime()),
                //2.设置执行周期(Trigger)
                triggerContext -> {
                    //2.1 从数据库获取执行周期
                    String cron = cronMapper.getCron();
                    //2.2 合法性校验.
                    if (StringUtils.isEmpty(cron)) {
                        // Omitted Code ..
                    }
                    //2.3 返回执行周期(Date)
                    return new CronTrigger(cron).nextExecutionTime(triggerContext);
                }
        );
    }*/
}
